package com.app.view.component.dialogs.pkResultView 
{
	import flash.display.MovieClip;
	
	import org.component.TabBar;
	import org.component.item.TabBarItem;
	import org.component.events.TabBarEvent;
	
	import com.peachcastle.core.Display;
	
	import com.app.view.component.dialogs.PkResultView;
	
	import com.app.model.data.UserData;
	
	import com.peachcastle.tools.Assert;
	import com.peachcastle.debug.Log;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class Tab extends Display 
	{
		public static const SEAT_COUNT:int = 7;
		
		public static const OFF_SET:int = 2;
		
		private var _parent:PkResultView = null;
		
		private var _connection:Array = [];
		
		private var _tab:TabBar = null;
		
		public function Tab(ui:MovieClip = null, parent:PkResultView = null) 
		{
			_parent = parent;
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			_tab = new TabBar();
			for (var i:int = 0; i < SEAT_COUNT; i++)
			{
				Assert.hasNot(assest, "item_" + i, 'Tab');
				
				_tab.addItem(assest["item_" + i], 'test_' + i);
			}
			_tab.hideAll();
		}
		
		override protected function configEventListeners():void
		{
			super.configEventListeners();
			
			_tab.addEventListener(TabBarEvent.TABBAR_SELECT, onSelect);
		}
		
		private function onSelect(e:TabBarEvent):void
		{
			Log.debug("onSelect", e.item.index);
			
			if(e.item.index >= 0 && e.item.index < 7)
				_parent.showResult(e.item.index + OFF_SET);
		}
		
		public function hideAll():void
		{
			_tab.hideAll();
		}
		
		public function showOne(user:UserData):void
		{
			var t:TabBarItem = _tab.getIndexByItem(user.seatid - OFF_SET);
			if (t)
			{
				t.label = user.name;
				t.visible = true;
				_tab.selectIndex = t.index;
			}
		}
	}

}